package love.simbot.example.utils.image;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import love.simbot.example.entity.Image.ImageData;
import love.simbot.example.utils.http.HttpUtils;

public class ImageUtils {

    private static final String url = "https://api.xiaobaibk.com/api/pic/acg-1/?return=json";

    public static ImageData getImage(){
        String tool = HttpUtils.getTool(url, null);
        ObjectMapper om = new ObjectMapper();
        om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
        if(tool != null){
            ImageData imageData = null;
            try {
                imageData = om.readValue(tool, ImageData.class);
                return imageData;
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
        }
        return new ImageData();
    }

}
